
:-if(current_prolog_flag(dialect, sicstus)).

:- use_module(library(file_systems)).

%%      flatten(+List1, ?List2) is det.
%
%       Is true it List2 is a non nested version of List1.
%
%       @deprecated     Ending up needing flatten/3 often indicates,
%                       like append/3 for appending two lists, a bad
%                       design.  Efficient code that generates lists
%                       from generated small lists must use difference
%                       lists, often possible through grammar rules for
%                       optimal readability.
%       @see append/2

flatten(List, FlatList) :-
        flatten(List, [], FlatList0), !,
        FlatList = FlatList0.

flatten(Var, Tl, [Var|Tl]) :-
        var(Var), !.
flatten([], Tl, Tl) :- !.
flatten([Hd|Tl], Tail, List) :- !,
        flatten(Hd, FlatHeadTail, List),
        flatten(Tl, Tail, FlatHeadTail).
flatten(NonList, Tl, [NonList|Tl]).




:-endif.